import io.vertx.core.file.FileSystem
import io.vertx.kotlin.coroutines.await
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

class LogHelper(private val fs: FileSystem) {
  fun getNow(): String {
    val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
    return LocalDateTime.now().format(formatter).toString()
  }

  suspend fun addLog(message:String){
    val file = "./history.log"
    if(!fs.exists(file).await()) {
      fs.createFile(file).await()
    }
    fs.readFile(file)
      .await()
      .appendString("[${getNow()}] $message\n")
      .also {
        fs.writeFile(file, it)
      }
  }
}
